<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<body>

<div id="page-content">
    <div class="row">

        <div class="col-lg-12">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">成员信息</h3>
                </div>
                <div class="panel-body">
                    <div class="form-inline">
                        <div class="row">
                            <div class="col-sm-12 table-toolbar-left">
                                <btn id="btn_add_member" class="btn btn-primary btn-sm">
                                    <i class="ti-plus"> </i> 新增成员
                                </btn>
                            </div>
                        </div>
                    </div>
                    <div class="table-jqgrid">
                        <table id="member_table"></table>
                        <div id="member_page"></div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

</body>

<script th:inline="javascript">
    $(function () {

        init_grid_member();

    });


    //查看职责信息
    function fn_users_actions_query(id) {
        __open_dialog_form_read('职责设置<button id="all-user-duty" type="button" class="btn btn-default" style="position: absolute; top: 10px; right: 10px">查看已拥有职责</button>', '/main/duty/memberDutyInput/' + id, function (dialogRef) {
            dialogRef.close();
        });
    }

    function init_grid_member() {

        __init_jqgrid('member_table', 'member_page', '/main/member/list',
            ['用户名称', '用户名', '邮箱', '手机号','登陆时间', '微信', "职责信息", '操作', 'id'],
            [
                {name: 'name', index: 'name', width: 250, sortable: true, stype: 'text', searchoptions: {sopt: ['cn']}},
                {name: 'username', index: 'username', width: 250, sortable: true, search: true, stype: 'text', searchoptions: {sopt: ['cn']}},
                {name: 'email', index: 'email', width: 250, sortable: true, search: true, stype: 'text', searchoptions: {sopt: ['cn']}},
                {name: 'phone', index: 'phone', width: 250, sortable: true, search: true, stype: 'text', searchoptions: {sopt: ['cn']}},
                {name: 'loginTime', index: 'loginTime', width: 250, sortable: true, search: true, stype: 'text', searchoptions: {sopt: ['cn']}},
                {name: 'wxName', index: 'wxName', width: 120, sortable: false, search: false},
                {name: 'roleBtn', index: 'roleBtn', width: 120, sortable: false, search: false, formatter: btnDutyInfo},
                {name: 'act', index: 'act', width: 120, fixed: true, sortable: false, search: false, formatter: actFormat},
                {name: 'id', index: 'id', width: 100, key: true, hidden: true, hidedlg: true}
            ]
        );

    }

    function btnDutyInfo(cellvalue, options, cell) {
        if (cellvalue != "") {
            var cl = cell["ifMain"];
            var id = cell["id"];
            if (cl != "" && typeof(cl) != "undefined") {
                var btn = "<button class='btn btn-warning btn-sm' data-original-title='职责信息'  onclick=\"fn_users_actions_query('" + id + "');\"><i class='fa fa-eye'></i> 职责信息</button>";
            } else {
                var btn = "<button class='btn btn-default btn-sm' data-original-title='职责信息'  onclick=\"fn_users_actions_query('" + id + "');\"><i class='fa fa-eye'></i> 职责信息</button>";
            }
            return btn;
        }
        return false;
    }

    function actFormat(cellvalue, options, rowObject) {
        var id = rowObject.id;
        cellvalue = '<button class="btn btn-default btn-xs" data-original-title="编辑" onclick="fn_member_edit(\'' + id + '\');"><i class="fa fa-pencil-square-o"> </i> 编辑</button> ';
        return cellvalue;
    }

    $('#btn_add_member').click(function () {
        __open_dialog_form('新增成员', '/main/member/create', function (dialogRef) {
            var callback = function (data) {
                if (data && data.state === 1) {
                    dialogRef.close();
                    __reflash_jqgrid("member_table");
                } else {
                    dialogRef.enableButtons();
                }
            };
            if (fn_member_create_save(callback) === false) {
                dialogRef.enableButtons();
            }
        });
        return false;
    });

    function fn_member_edit(id) {
        __open_dialog_form('编辑成员信息', '/main/member/update/' + id, function (dialogRef) {
            var callback = function (data) {
                if (data && data.state === 1) {
                    dialogRef.close();
                    __reflash_jqgrid("member_table");
                } else {
                    dialogRef.enableButtons();
                }
            };
            if (fn_member_update_save(callback) === false) {
                dialogRef.enableButtons();
            }
        });
    }
</script>

</html>